package com.yeskery.nut.web.demo.controller;

import com.yeskery.nut.annotation.api.Api;
import com.yeskery.nut.annotation.api.ApiGroup;
import com.yeskery.nut.annotation.api.ApiParam;
import com.yeskery.nut.annotation.bean.Autowired;
import com.yeskery.nut.annotation.web.GetMapping;
import com.yeskery.nut.annotation.web.PathVariable;
import com.yeskery.nut.annotation.web.RequestMapping;
import com.yeskery.nut.annotation.web.RestController;
import com.yeskery.nut.web.demo.biz.UserBiz;
import com.yeskery.nut.web.demo.common.R;
import com.yeskery.nut.web.demo.common.UserContext;
import com.yeskery.nut.web.demo.domain.Wallet;
import com.yeskery.nut.web.demo.dto.UserDto;

import java.util.List;

/**
 * 用户controller
 * @author Yeskery
 * 2023/7/28
 */
@ApiGroup("用户")
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserBiz userBiz;

    /**
     * 查询所有用户信息列表
     * @return
     */
    @Api(value = "查询所有用户信息列表", responseClass = UserDto.class)
    @GetMapping("/list")
    public R<List<UserDto>> getUserList() {
        return R.ok(userBiz.getUserList());
    }

    /**
     * 获取指定用户信息
     * @return
     */
    @Api(value = "获取指定用户信息", responseClass = UserDto.class)
    @GetMapping("/detail/{userId}")
    public R<UserDto> getUserList(@ApiParam("用户id") @PathVariable("userId") Integer userId) {
        return R.ok(userBiz.getUser(userId));
    }

    /**
     * 查询当前登录的用户信息列表
     * @return
     */
    @Api(value = "查询当前登录的用户信息列表", responseClass = UserDto.class)
    @GetMapping("/info")
    public R<UserDto> getCurrentUser() {
        return R.ok(UserContext.getUser());
    }

    /**
     * 查询当前登录的用户钱包信息
     * @return
     */
    @Api(value = "查询当前登录的用户钱包信息", responseClass = Wallet.class)
    @GetMapping("/wallet")
    public R<Wallet> getCurrentUserWallet() {
        return userBiz.getCurrentUserWallet();
    }
}
